package me.ingxin.android.permission2.ext

import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.Settings
import androidx.annotation.RequiresApi
import me.ingxin.android.permission2.PERMISSION_POST_NOTIFICATIONS
import me.ingxin.android.permission2.targetSdkVersion

/**
 * Created on 2023/7/19 by yin
 * 在Android13以下通知权限申请
 */
internal class NotificationPermissionTask : BaseSpecialPermissionsTask() {
    override val permission = PERMISSION_POST_NOTIFICATIONS

    override fun showRequestPermission(context: Context): Boolean {
        //在Android13以上通知权限变成了普通权限，就不需要申请
        return Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || context.targetSdkVersion < Build.VERSION_CODES.TIRAMISU
    }

    @RequiresApi(Build.VERSION_CODES.O)
    override fun crateInput(context: Context): Intent {
        return Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).apply {
            putExtra(Settings.EXTRA_APP_PACKAGE, context.packageName)
        }
    }
}